<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<style>
    .ball {
        width: 30px;
        height: 30px;
        background-color: brown;
        border-radius: 50%;
    }
</style>

<body>
    <div id='app'>
        <button @click="flag=!flag">切换动画</button>
        <transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter"
            :duration="{enter:1000,leave:500}">
            <div v-show="flag" class="ball"></div>
        </transition>
    </div>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                flag: false
            },
            methods: {
                beforeEnter(el) {
                    el.style.transform = 'translate(0, 0)'
                },
                enter(el, done) {
                    el.offsetHeight;
                    el.style.transition = 'all 1s ease'
                    el.style.transform = 'translate(800px, 400px)'
                    done()
                },
                afterEnter(el) {
                    this.flag = false
                }
            }
        })
    </script>
</body>

</html>